﻿using GalaSoft.MvvmLight.CommandWpf;
using GEPL.StandardModulesLibrary.Models;
using PropertyChanged;
using System.Collections.ObjectModel;
using System.Windows.Input;

namespace GEPL.StandardModulesLibrary.ViewModels.Common
{
    [ImplementPropertyChanged]
    public class SetVariableViewModel
    {
        public ObservableCollection<Variable> VariablesList { get; set; }

        public Variable SelectedVariable { get; set; }

        public ICommand AddCommand { get; set; }

        public ICommand RemoveCommand { get; set; }

        public SetVariableViewModel()
        {
            VariablesList = new ObservableCollection<Variable>();
            InitCommands();
        }

        private void InitCommands()
        {
            AddCommand = new RelayCommand(Add);
            RemoveCommand = new RelayCommand(Remove, () => SelectedVariable != null);
        }

        public void Add()
        {
            VariablesList.Add(new Variable());
        }

        public void Remove()
        {
            if (SelectedVariable == null)
                return;
            VariablesList.Remove(SelectedVariable);
        }
    }
}